package com.zz.ecommerce.assistSysManage.assistSys;

import com.zz.ecommerce.assistSysManage.assistSys.bean.TAssistSys;
import com.zz.ecommerce.assistSysManage.assistSys.bean.TAssistSysInter;
import com.zz.ecommerce.assistSysManage.assistSys.service.TAssistSysService;
import com.zz.ecommerce.common.CommonDao;
import com.zz.ecommerce.common.GridRequest;
import com.zz.ecommerce.common.GridResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * 辅助系统controller
 */
@Controller
@RequestMapping("/assistSys")
public class TAssistSysController {
    @Autowired
    CommonDao commonDao;
    @Autowired
    TAssistSysService tAssistSysService;

    /**
     * 辅助系统列表
     *
     * @return
     */
    @RequestMapping(value = "tAssistSysManager", method = RequestMethod.GET)
    public String TAssistSysManager() {
        return "assistSysManager/assistSys/tassistsys_manager";
    }

    /**
     * 获取辅助系统分页列表
     *
     * @param gridRequest
     * @param tAssistSys
     * @return
     */
    @RequestMapping(value = "qryTAssistSysPage", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public GridResult<TAssistSys> qryTAssistSysPage(GridRequest gridRequest, TAssistSys tAssistSys) {
        List<TAssistSys> list = commonDao.pageWhere("T_ASSIST_SYS", tAssistSys, gridRequest.getStart(), gridRequest.getEnd(), "", "");
        long count = commonDao.countWhere("T_ASSIST_SYS", tAssistSys, "");
        return new GridResult<TAssistSys>(list, gridRequest, count);
    }

    /**
     * 删除辅助系统数据
     *
     * @param sysIds
     * @return
     */
    @RequestMapping(value = "deleteTAssistSys", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public String deleteTAssistSys(String sysIds) {
        try {
            return tAssistSysService.deleteTAssistSys(sysIds);
        } catch (Exception e) {
            return "保存失败：" + e.getMessage();
        }
    }

    /**
     * 保存辅助系统修改
     *
     * @param session
     * @param tAssistSys
     * @return
     */
    @RequestMapping(value = "saveTAssistSys", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public String saveTAssistSys(HttpSession session, TAssistSys tAssistSys) {
        try {
            return tAssistSysService.saveAssistSys(tAssistSys);
        } catch (Exception e) {
            return "保存失败：" + e.getMessage();
        }
    }

    /**
     * 获得辅助系统详情
     *
     * @param tAssistSys
     * @param modelMap
     * @return
     */
    @RequestMapping(value = "getTAssistSysDetail", method = {RequestMethod.GET, RequestMethod.POST})
    public String getTAssistSysDetail(TAssistSys tAssistSys, String modify, ModelMap modelMap) {
        TAssistSys tAssistSysDetail = (TAssistSys) commonDao.qryOneCommon("T_ASSIST_SYS", tAssistSys, "");
        modelMap.put("tAssistSys", tAssistSysDetail);
        modelMap.put("modify", "false".equals(modify));
        return "assistSysManager/assistSys/tassistsys_detail";
    }

    /**
     * 接口列表
     *
     * @return
     */
    @RequestMapping(value = "tAssistSysInterManager", method = RequestMethod.GET)
    public String TAssistSysInterManager() {
        return "assistSysManager/assistSys/tassistsysinter_manager";
    }

    /**
     * 接口分页列表
     *
     * @param gridRequest
     * @param tAssistSysInter
     * @return
     */
    @RequestMapping(value = "qryTAssistSysInterPage", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public GridResult<TAssistSysInter> qryTAssistSysInterPage(GridRequest gridRequest, TAssistSysInter tAssistSysInter) {
        List<TAssistSysInter> list = commonDao.pageWhere("T_ASSIST_SYS_INTER", tAssistSysInter, gridRequest.getStart(), gridRequest.getEnd(), "", "");
        long count = commonDao.countWhere("T_ASSIST_SYS_INTER", tAssistSysInter, "");
        return new GridResult<TAssistSysInter>(list, gridRequest, count);
    }

    /**
     * 保存接口
     *
     * @param session
     * @param tAssistSysInter
     * @return
     */
    @RequestMapping(value = "saveTAssistSysInter", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public String saveTAssistSysInter(HttpSession session, TAssistSysInter tAssistSysInter) {
        try {
            return tAssistSysService.saveAssistSysInter(tAssistSysInter);
        } catch (Exception e) {
            return "保存失败：" + e.getMessage();
        }
    }

    /**
     * 删除辅助系统数据
     *
     * @param interIds
     * @return
     */
    @RequestMapping(value = "deleteTAssistSysInter", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public String deleteTAssistSysInter(String interIds) {
        try {
            return tAssistSysService.deleteTAssistSysInter(interIds);
        } catch (Exception e) {
            return "保存失败：" + e.getMessage();
        }
    }

    /**
     * 接口详情页
     *
     * @param tAssistSysInter
     * @param modelMap
     * @return
     */
    @RequestMapping(value = "getTAssistSysInterDetail", method = {RequestMethod.GET, RequestMethod.POST})
    public String getTAssistSysInterDetail(TAssistSysInter tAssistSysInter, String modify, ModelMap modelMap) {
        TAssistSysInter tAssistSysInterDetail = (TAssistSysInter) commonDao.qryOneCommon("T_ASSIST_SYS_INTER", tAssistSysInter, "");
        modelMap.put("tAssistSysInter", tAssistSysInterDetail);
        modelMap.put("modify", "false".equals(modify));
        return "assistSysManager/assistSys/tassistsysinter_detail";
    }
}
